package com.jichangxiu.system.action;

import com.jichangxiu.common.entity.vo.PageResult;
import com.jichangxiu.system.entity.dto.edit.EditSysLog;
import com.jichangxiu.system.entity.dto.query.QuerySysLog;
import com.jichangxiu.system.entity.vo.SysLogVo;
import com.jichangxiu.system.service.SysLogService;
import com.jichangxiu.framework.action.BaseAction;
import com.jichangxiu.common.annotation.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;

/**
 * SysLogAction:
 *
 * @author JiChangXiu
 * @create 2024-06-28 13:44:26
 */
@Slf4j
@Rest("/system/log")
@Tag(name = "系统日志控制器")
public class SysLogAction extends BaseAction {

    @Resource
    private SysLogService sysLogService;

    /**
     * 修改系统日志
     *
     * @param editSysLog 修改系统日志视图对象
     * @return 是否成功
     */
    @Put
    @Limit
    @Repeat
    @Log(remark = "修改系统日志")
    @Operation(summary = "修改系统日志")
    @PreAuthorize("@jcx.hasPower('system:log:edit')")
    public String edit(@RequestBody EditSysLog editSysLog) {
        return str(sysLogService.edit(editSysLog));
    }

    /**
     * 根据主键查询系统日志
     *
     * @param id       系统日志主键
     * @param isExtend 是否扩展
     * @return 系统日志详情
     */
    @Get("/{id}")
    @Operation(summary = "根据主键查询系统日志")
    @PreAuthorize("@jcx.hasPower('system:log:info')")
    public SysLogVo info(@PathVariable("id") @NotBlank(message = "主键不能为空") String id, @RequestParam(value = "isExtend", required = false, defaultValue = "false") Boolean isExtend) {
        return sysLogService.info(id, isExtend);
    }

    /**
     * （可分页）查询系统日志列表
     *
     * @param querySysLog 查询视图对象
     * @return （分页）系统日志列表
     */
    @Get("/lists")
    @Operation(summary = "（可分页）查询系统日志列表")
    @PreAuthorize("@jcx.hasPower('system:log:lists')")
    public PageResult lists(@ParameterObject QuerySysLog querySysLog) {
        return pageResult(sysLogService.lists(querySysLog));
    }

}